package me.minecraft.plugin.playerride.manager;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

/**
 * @author langle__
 * @version 1.0
 */
public class MainManager {

    public static final MainManager INSTANCE = new MainManager();

    private final Map<UUID, UUID> riderTargetMap = new HashMap<>();
    private final Set<UUID> protectPlayers = new HashSet<>();

    private MainManager() {
    }

    public void setRiderTarget(@NotNull Player player, @NotNull Player target) {
        riderTargetMap.put(player.getUniqueId(), target.getUniqueId());
    }

    public void removeRiderTarget(@NotNull Player player) {
        riderTargetMap.remove(player.getUniqueId());
    }

    public boolean hasRiderTarget(@NotNull Player player) {
        return riderTargetMap.containsKey(player.getUniqueId());
    }

    @Nullable
    public Player getRiderTarget(@NotNull Player player) {
        UUID uuid = riderTargetMap.get(player.getUniqueId());
        if (uuid == null) return null;
        return Bukkit.getPlayer(uuid);
    }

    public void enableProtection(@NotNull Player player) {
        protectPlayers.add(player.getUniqueId());
    }

    public void disableProtection(@NotNull Player player) {
        protectPlayers.remove(player.getUniqueId());
    }

    public boolean isProtected(@NotNull Player player) {
        return protectPlayers.contains(player.getUniqueId());
    }

}
